<template>
	<view class="wrap">
		<!-- 开启消息提示 -->
		<u-toast ref="uToast" />
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎登录校园招聘</view>
			<input class="u-border-bottom" v-model="userInfo.username" placeholder="请输入账号" />
			<input class="u-border-bottom" v-model="userInfo.password" placeholder="请输入密码" />
			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">登录</button>
			<view class="alternative">
				<!-- <view class="password">找回密码</view> -->
				<!-- <view class="issue">注册</view> -->
			</view>
		</view>

	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo:{
				username:'xiaoming',
				password:'123456'
			}
		}
	},
	computed: {
		inputStyle() {
			let style = {};
			if(this.$u.test.rangeLength(this.userInfo.username, [3, 10])&&this.$u.test.rangeLength(this.userInfo.password, [3, 10])) {
				style.color = "#fff";
				style.backgroundColor = this.$u.color['primary'];
			}
			return style;
		}
	},
	methods: {
		submit() {
			//预校验
			if(!this.$u.test.rangeLength(this.userInfo.username, [3, 10])||!this.$u.test.rangeLength(this.userInfo.password, [3, 10])) return;
			// console.log(this.userInfo)
			//登录
			uniCloud.callFunction({
				name: "user",
				data: {
					userInfo:this.userInfo,
					type: "login"
				},
				success: (res) => {
					// console.log("error！",res);
					if(res.result.status!=200){
						// console.log("error！",res);
						//提示消息
						this.$refs.uToast.show({
								title: res.result.msg,
								type: 'error',//提示文字
								url: '/pages/user/index',//跳转
								position:"top",
								duration:'1000',//时间
								icon:false
								})
						return;
					}
					//登录成
					//设置本地存储
					uni.setStorageSync('storage_user', res.result.data);
					//提示消息
					this.$refs.uToast.show({
							title: res.result.msg,
							type: 'success',//提示文字
							position:"top",
							icon:false,
							duration:'1000',//时间
							})
					//跳转
					this.j();
					// console.log("登录成功")
				},
				fail: (err) => {
					console.log(err)
				}
			})
			
		},
		showToast() {
						this.$refs.uToast.show({
							title: '登录成功',
							type: 'success',
							url: '/pages/user/index'
						})
					},
					j(){
						setTimeout(()=>{
							    uni.switchTab({
							    url: '/pages/my/my'
							    });
						},1100)
					}
	},
	onLoad() {
	
			// const token = uni.getStorageSync('storage_key');
			  // uni.setStorageSync('storage_key', 'hello');
		
		}
};
</script>

<style lang="scss" scoped>
	.u-border-bottom{
		margin-bottom: 35rpx !important;
	}
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;

		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-type-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		.getCaptcha {
			background-color: rgb(179, 207, 253);
			color: $u-tips-color;
			border: none;
			font-size: 30rpx;
			padding: 12rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		.loginType {
			display: flex;
			padding: 350rpx 150rpx 150rpx 150rpx;
			justify-content:space-between;
			
			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: $u-content-color;
				font-size: 28rpx;
			}
		}
		
		.hint {
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: $u-tips-color;
			
			.link {
				color: $u-type-warning;
			}
		}
	}
}
</style>
